<template>
  <div class="user">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form
        size="small"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="关键词">
          <el-input
            v-model="formInline.real_name"
            placeholder="姓名|手机号|店铺名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="分类">
          <el-select v-model="formInline.cate_name" placeholder="请选择">
            <el-option label="全部" value=""></el-option>
            <el-option label="外卖点" value="外卖点"></el-option>
            <el-option label="饭店" value="饭店"></el-option>
            <el-option label="夜宵摊" value="夜宵摊"></el-option>
            <el-option label="其他" value="其他"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="注册时间">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker
              v-model="formInline.reg_date"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table
          size="small"
          :data="tableData"
          border
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column
            prop="apply_id"
            label="ID"
            width="80"
          ></el-table-column>
          <el-table-column prop="store_name" label="店铺名称"></el-table-column>
          <el-table-column prop="nickName" label="账户昵称"></el-table-column>
          <el-table-column prop="real_name" label="店长姓名"></el-table-column>
          <el-table-column prop="mobile" label="店长手机号"></el-table-column>
          <el-table-column prop="cate_name" label="分类名称"></el-table-column>
          <el-table-column prop="address" label="详细地址"></el-table-column>
          <el-table-column prop="house_number" label="门牌号"></el-table-column>
          <el-table-column prop="photo" label="门头照片">
            <template slot-scope="scope">
              <img :src="scope.row.photo" width="30px" height="30px" />
            </template>
          </el-table-column>
          <el-table-column
            prop="apply_status"
            label="审核"
            width="80"
            align="center"
          >
            <template slot-scope="scope">
              <p
                v-if="scope.row.apply_status.value == 10"
                @click="auditHandle(scope.row)"
                style="color:#C0C4CC;cursor: pointer;text-decoration: underline"
              >
                待审核
              </p>
              <span
                v-else-if="scope.row.apply_status.value == 20"
                style="color:green"
                >通过</span
              >
              <p
                v-else-if="scope.row.apply_status.value == 30"
                style="color:red;cursor: pointer;"
                @click="auditHandle(scope.row)"
              >
                不通过
              </p>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="apply_status" label="审核状态">
          </el-table-column> -->
          <el-table-column
            prop="apply_time"
            label="注册时间"
            width="140"
          ></el-table-column>
          <el-table-column fixed="right" label="操作" width="170">
            <template slot-scope="scope">
              <el-button
                @click="editClick(scope.row)"
                type="text"
                size="small"
                v-auth="'/stall/category'"
                >设置分类
              </el-button>
              <el-button
                @click="editProClick(scope.row)"
                type="text"
                size="small"
                v-auth="'/stall/product'"
                >设置商品
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--审核-->
      <audit :open="auditOpen" @close="closeAudit" :form="auditRow"></audit>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import StallApi from "@/api/stall.js";
import Sortable from 'sortablejs';
export default {
  components: {
    Sortable
  },
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        real_name: "",
        cate_name: "",
        reg_date: ""
      },
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      userModel: {},
      auditOpen: false,
      auditRow: {}
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },

    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = self.formInline;
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      StallApi.stallList(Params, true)
        .then(data => {
          self.loading = false;
          self.tableData = data.data.list.data;
          self.totalDataNumber = data.data.list.total;
        })
        .catch(error => {
          self.loading = false;
        });
    },

    /*搜索查询*/
    onSubmit() {
      let self = this;
      self.loading = true;
      let Params = self.formInline;
      self.getTableList();
    },

    /*打开添加*/
    addClick(item) {
      this.userModel = item;
      this.open_add = true;
    },
    /*打开编辑*/
    editClick(item) {
      let self = this;
      let params = item.apply_id;
      this.$router.push({
        path: "/stall/category",
        query: {
          stall_id: params,
          scene: 'edit'
        }
      });
    },
    
    /*打开编辑*/
    editProClick(item) {
      let self = this;
      let params = item.apply_id;
      this.$router.push({
        path: "/stall/product",
        query: {
          stall_id: params,
          scene: 'edit'
        }
      });
    },

    /*关闭弹窗*/
    closeDialogFunc(e, f) {
      if (f == "add") {
        this.open_add = e.openDialog;
        if (e.type == "success") {
          this.getTableList();
        }
      }
      if (f == "edit") {
        this.open_edit = e.openDialog;
        if (e.type == "success") {
          this.getTableList();
        }
      }
    },

    /*删除用户*/
    deleteClick(row) {
      let self = this;
      self
        .$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
        .then(() => {
          self.loading = true;
          StallApi.deleteStall(
            {
              apply_id: row.apply_id
            },
            true
          )
            .then(data => {
              self.loading = false;
              if (data.code == 1) {
                self.$message({
                  message: "恭喜你，用户删除成功",
                  type: "success"
                });
                self.getTableList();
              } else {
                self.loading = false;
              }
            })
            .catch(error => {
              self.loading = false;
            });
        })
        .catch(() => {
          self.loading = false;
        });
    },
    auditHandle(row) {
      this.auditRow = row;
      this.auditOpen = true;
    },
    closeAudit(value) {
      this.auditOpen = false;
      this.getTableList();
    }
  }
};
</script>
<style></style>
